package method.Reference;

@FunctionalInterface
interface Operation {
    int operation(int a, int b);
}

interface Creater<T> {
    T get();
}

interface TestInt {
    int cp(Test test1, Test test2);
}

class Test {

    private Test() {
        System.out.println("default constroct be call");
    }

    public static Test create(Creater<Test> creater) {
        return creater.get();
    }

    private int operate(int a, int b, Operation operation) {
        return operation.operation(a, b);
    }

    private static int add(int a, int b) {
        return a + b;
    }

    private int sub(int a, int b) {
        return a - b;
    }

    public int testM(Test test) {
        return 0;
    }

    public void test(TestInt testInt) {
        Test t1 = Test.create(Test::new);
        Test t2 = Test.create(Test::new);
        testInt.cp(t1, t2);
    }

    /**
     * 构造方法引用
     * 使用方式：Class::new
     * Test test = Test.create(Test::new);
     *
     * 静态方法引用
     * 使用方式：Class::staticMethod
     * test.operate(1, 2, Test::add);
     *
     * 对象的实例方法引用
     * 使用方式：Class::method
     * test.test(Test::testM);
     * @param args
     */
    public static void main(String[] args) {
        Test test = Test.create(Test::new);
        System.out.println("=====" + test);

        int operate = test.operate(1, 2, test::sub);
        System.out.println("=====operate" + operate);

        test.test(Test::testM);
    }

}